using UnityEditor;
using UnityEngine;

namespace UnityXEditor
{
    public static class EditorMenuTool
    {
        /// <summary>
        /// 根据指定对象执行菜单
        /// </summary>
        /// <param name="menu">菜单</param>
        /// <param name="objects">对象</param>
        /// <returns></returns>
        public static bool ExecuteMenuItem(string menu, Object[] objects)
        {
            var flags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static;
            var method = typeof(EditorApplication).GetMethod("ExecuteMenuItemWithTemporaryContext", flags);
            var value = method.Invoke(null, new object[] { menu, objects });
            return (bool)value;
        }
    }
}